package datastructure.list;

/**
 * Description：
 * Author: zhangc
 * Date：2017/6/15 22:41
 */
public class ArrayListStack<T> implements Stack<T> {

    private List<T> list = new ArrayList<>();

    @Override
    public void push(T element) {
        list.append(element);
    }

    @Override
    public T pop() {
        return list.length() > 0 ? list.remove(list.length() - 1) : null;
    }

    @Override
    public T peek() {
        return list.length() > 0 ? list.get(list.length() - 1) : null;
    }

    @Override
    public boolean isEmpty() {
        return list.length() == 0;
    }
}
